|
|
|
|
|
|
|
is particularly slow. If the program uses a generic Transformation class object, the subroutine call is a bit slower than it would be if the program used a more specific class such as TransWave. It is certainly slower than calling a matrix/vector multiplication subroutine or performing the multiplication directly. |
|
|
|
|
|
|
|
|
Transformation objects also do not combine as well as matrices do. While building a combined transformation object is easy, that object executes the transformations it represents one at a time. On the other hand, you can combine as many transformation matrices as you like and still end up with a single matrix to represent the combined transformations. This capability is particularly important for complex operations that require many intermediate transformations. |
|
|
|
|
|
|
|
|
To reflect an object across an arbitrary line, for example, you must translate the line of reflection to the origin, rotate the line until it lies along the X axis, reflect the object, reverse the rotation, and finally translate the line back to where it starteda total of five transformations. Using matrices, you can accomplish all these steps with a single transformation. Using a transformation class, the program would need to perform each operation separately. |
|
|
|
|
|
|
|
|
Finally, although shape-distorting transformations are interesting, the standard matrix transformations described earlier are much more common. It would be nice to be able to treat all transformations in the same way, but making the most important transformations as efficient as possible is worth the extra effort. |
|
|
|
|
|
|
|
|
For small pictures, it is easy enough to redraw every part of the picture whenever you need to draw a piece of it. When you zoom in on one corner of the picture, redrawing everything is the easiest approach. Visual Basic takes care of cropping the picture at the viewport's boundaries. |
|
|
|
|
|
|
|
|
For complex pictures, however, this approach can be wasteful. If you have zoomed in on a small part of the picture, you might spend a lot of time drawing objects that are cropped off by Visual Basic. |
|
|
|
|
|
|
|
|
Example program Hexes1 lets you pan and zoom on a picture containing a 50-by-50 grid of small hexagons. On a 133MHz Pentium processor, the program takes more than two seconds to draw the picture at full scale. On slower computers, it may take much longer. |
|
|
|
|
|
|
|
|
If you zoom in on a tiny portion of the picture, it still takes more than two seconds to draw the picture, even though only a fraction of a second is needed to draw the visible part of the picture. Drawing a smaller portion of the picture is a little faster than drawing the whole thing because Visual Basic needs a little less time to clip part of the picture off than to draw it. Still, the program is wasting a lot of time drawing hexagons that are never displayed. |
|
|
|
|
|
|
|
|
This program also lets you select one of the hexagons by clicking it. When you click one, the program searches through its list of objects until it finds the hexagon that contains the point where you clicked. It then highlights that hexagon. The hexagons are ordered from bottom to top, so it takes the program longer to find hexagons near the |
|
|
|
|
|